package net.neptech.node;

import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.action.NodeAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


/**
 * @Author HuangZhengmin
 * @desc  人工审核节点 - 处理包含敏感词的内容
 * @Date 2025/8/19 16:26
 * @Version 1.0
 */
@Component
public class ManualReviewNode implements NodeAction {
  private static final Logger logger = LoggerFactory.getLogger(ManualReviewNode.class);

  @Autowired
  private ChatClient chatClient;

  @Override
  public Map<String, Object> apply(OverAllState state) {
    logger.info("进入人工审核节点");
    Map<String, Object> result = new HashMap<>();

    // 获取标准化前的症状
    String symptoms = (String) state.value("symptoms").orElse("");

    // 生成人工审核建议
    String prompt = String.format(
            "以下医疗咨询内容包含敏感术语，请提供审核建议: %s。" +
                    "1. 确认是否存在违规内容\n" +
                    "2. 如需修改，请提供修改建议\n" +
                    "3. 给出最终处理意见", symptoms);

    String reviewResult = chatClient.prompt()
            .user(prompt)
            .call()
            .content();

    // 记录审核结果并更新敏感标记为false（已审核）
    result.put("review_result", reviewResult);
    result.put("sensitive_flag", false);

    logger.info("人工审核完成: {}", reviewResult);
    return result;
  }
}